Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal APIs to intern a built string without a copy #1185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svaarala
Copy link
Owner

@svaarala svaarala commented Dec 13, 2016

For example, currently duk_concat() creates a fixed buffer for the final result size and writes all string parts into it. The result is then string converted. This means, in practice, that the final string exists in RAM in both the temporary buffer and the final duk_hstring for a brief period.

Improve this so that internal call sites can push a duk_hstring allocated to a certain size but with uninitialized data. The string would also not be tracked in the string table. The calling code could then write to the string data part e.g. as part of duk_concat(). Once the data part is done, the same duk_hstring allocation can be finished and be interned into the string table, and then becomes immutable.

If an error is thrown, garbage collection must deal with a string that needs to be freed but without existing in the string table. Other issues to deal with:

  • When the final string has been built, it may already be in the string table but this can't be known beforehand. Must allow the string just built to be discarded.
  • When using low memory "external strings", the external string can only happen when the string is finished. It may then be necessary to switch to an external string.

Tasks:

  • Come up with a useful internal API idiom
  • Convert current call sites needing this (concat, encoding, etc)
  • Maybe expose in the public API; how?
  • Releases entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant